package com.sailing.lianxi.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * 回环栅栏测试
 * @author Administrator
 *
 */
public class CyclicBarrierTest {

	public static void t1() {
		int threadNum = 2;
		final CyclicBarrier barrier = new CyclicBarrier(threadNum);
		for(int i=0;i<threadNum;i++) {
			new Thread() {
				public void run() {
						try {
							System.out.println("子线程"+Thread.currentThread().getName()+" 正在执行");
							Thread.sleep(3000);
							System.out.println("子线程"+Thread.currentThread().getName()+" 执行结束");
							barrier.await();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						System.out.println("所有线程执行完成 ,继续处理其他任务");
				};
			}.start();
		}
	}
	
	public static void main(String[] args) {
		t1();
	}
}
